import axios from './$http'


const cache = new Map();

const api = {
    clearCache() {
        cache.clear();
    }, async getAppScheduleList(data) {
        const result = await axios.post(`/hbos-business-thirdparty-integration/appointment/getAppScheduleList`, data);

        return result;
    }, async appointmentSync(locId, serviceDate, keywords) {
        const result = await axios.post(`/hbos-business-thirdparty-integration/appointment/sync`, {
            locId: locId,
            startDate: serviceDate,
            // includeDoctorIds: `and cp.CTPCP_Code ='${userId}'`,
            endDate: serviceDate,
            keywords: keywords
        });
        return result;
    }, async getScheduleDeptConfigDetail(deptId) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/dept/detail`, {
            deptId
        });

        return result;
    }, async getAppScheduleDeptList(data) {
        const result = await axios.post(`/hbos-business-thirdparty-integration/appointment/getAppScheduleDeptList`, data);
        return result;
    }, async querySyncLog(tid) {
        const result = await axios.post(`/hbos-business-thirdparty-integration/appointment/querySyncLog`, {
            tid: tid
        });
        return result;
    },

    async saveDeptConfig(data) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/dept/save`, data);
        return result;
    }, async saveSchedule(data) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/save`, data);
        return result;
    }, async submitSchedule(ids) {
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/submit`, {
            ids
        });
        return result;
    }, //relateRuleId
    async submitGenerate(scheduleRuleId) {
        const result = await axios.post(`/hbos-sdc/schedule/generate`, {
            scheduleRuleId
        });
        return result;
    }, //找到所有已保存的进行提交
    async listSchedule(deptId, expireDate, validDate) {
        const key = `listSchedule:${deptId}-${expireDate}-${validDate}`;
        const data = cache.get(key);

        if (data) {
            return data;
        }
        const result = await axios.post(`/hbos-business-charge-gydfy/schedule/list`, {
            deptId, expireDate, validDate
        });

        cache.set(key, result);

        return result;
    },

    async staffSearch(attrList) {
        // const key = `staffSearch`;
        // let data = cache.get(key);
        // if (!data) {
        //     data = new Map();
        //     cache.set(key, data);
        // }
        // let resultList = [];
        // let attrListTemp = [];
        // for (const attr of attrList) {
        //     const attrData = data.get(attr);
        //     if (attrData == null) {
        //         attrListTemp.push(attr);
        //     } else {
        //         resultList.push(attrData);
        //     }
        // }
        // if (attrListTemp.length <= 0) {
        //     return resultList;
        // }
        const result = await axios.post(`/gw-api/hbos-business-thirdparty-integration/common/osc/staffSearch`, {
            orgId: 20001001, attrList
        });
        return result;
    },

    async deptSearch(attrList) {
        const result = await axios.post(`/gw-api/hbos-business-thirdparty-integration/common/osc/deptSearch`, {
            orgId: 20001001, attrList
        });
        return result;
    }, async listLocation(deptId) {
        const key = `listLocation:${deptId}`;
        const data = cache.get(key);

        if (data) {
            return data;
        }
        const result = await axios.post(`/hbos-sdc/schedule/clinic/location`, {
            deptId,
        });
        cache.set(key, result);
        return result;
    },


    async getShiftList() {
        const key = `getShiftList`;
        const data = cache.get(key);

        if (data) {
            return data;
        }
        const result = await axios.post(`/hbos-atc/shift/list`, {
            "type": "FH0101.05"
        });
        cache.set(key, result);
        return result;
    }, async listServiceItemManagementCategoryByCode() {
        const result = await axios.post(`/hbos-business-charge-gydfy/service_item/schedule/listServiceItemManagementCategoryByCode`, {
            "code": "FH0101.05"
        });
        return result;
    }, async getWeek() {
        const result = await axios.post(`/hbos-sdc/schedule/week`, {});
        return result;
    }
}

export default api;